Take First / Middle And Last Name And Print Initials
Oct 14, 2014
String firstName = "John";
String middleName = "Fitzgerald";
String lastName = "Kenady";
System.out.println(firstName.charAt(0) + middleName.charAt(0) + lastName.charAt(0));
So, while doing some homework, I came across an oddity. The assignment was to take a first, middle and last name and print the initials. The above code was my first solution, however it prints the number 219 instead of JFK.
For the record, I worked around it by using the .substring method instead.
View Replies
ADVERTISEMENT
Jan 16, 2015
I am trying to align the core/middle side color of a cube, index 4, with the bottom middle color of the same side, index 7. (Each side has values 0-8 where 0 - is the top left corner, 1 is the top mid corner, 2 is the top right corner, 3 is the middle left corner, etc).
In addition to lining up those two colors, I am also making sure that the neighbor color of index 7(the color that it is attached), in this case the bottom color, matches with the top core/middle color. I will attach some pictures and a print out to show what I am talking about...
However, in my code when I am trying to align all of these up together, it does not go into the while loop. Each of the loops essentially is trying to get a match of same color with index 4 and 7, as well as making sure that index 7's neighbor color (the bottom color, in this case) matches with the top color.
Here is what I have tried:
private void alignSideColor(){//make the bottom colors neighbor match with a middle side value and rotate it to the top, for the top cross
if(cube.bottom.square[1].charAt(0) == topColor){
while(cube.front.square[7].charAt(0) != frontColor && cube.bottom.square[1].charAt(0) != topColor){
rotateBottomClockwise(1);
System.out.println("Trying to align side color...");
[Code] .....
The print out of the ELSE IF is:
alignment is: W-G and tops: R-R
NOW ITS ALIGNED
even though the sides, index 4 and 7, are NOT aligned with each other
I have also tried the same thing but with out the 2nd condition in each while loop, and although is DOES enter the while loop, it does not perform correctly -- index 4 and 7 WILL have matches colors, but it does not check to see if index 7's neighbor matches with the top color.
Here is how it prints out
** ** ** G7 B6 Y1 ** ** **//this portion is the back of the cube
** ** ** R6 W5 O4 ** ** **
** ** ** R3 W2 O1 ** ** **
B3 G4 Y9 W9 O8 Y7 W3 B4 G9//this portion is the left, top, and right of the cube
B2 G5 R8 W4 R5 Y6 O2 B5 G8
O7 W8 R9 B7 B8 B9 R1 R4 R7
** ** ** O3 O6 O9 ** ** **//this portion is the front of the cube
** ** ** Y2 Y5 Y8 ** ** **
** ** ** B1 G6 W7 ** ** **
** ** ** Y3 Y4 G1 ** ** **//this portion is the bottom the cube
** ** ** R2 O5 G2 ** ** **
** ** ** W1 W6 G3 ** ** **
Here is the cube showing the top, left and front side
Here is the left and bottom side. As you can see index 4, G5 -- yes that is a 5 lol -- does not have the same color as index 7, W8.
I need to rotate the bottom until W8 is aligned with a middle white value. An examples of a neighbor is: W8-R2
View Replies
View Related
Jan 5, 2014
Following is the code for my assignment where a user inputs his full name in a string from keyboard. It should be done using BufferedReader. The program will give his initials as output.
############################
For example: User inputs-> Ram Kumar Das
Program Returns-> R.K.D.
I am written the following piece of code. It does not return the correct output. If "Ram Kumar Das" is given as input, it gives R.K.K. as output. Arrays and objects are strictly not allowed.
Java Code:
import java.io.*;
public class Assignment
{
static int i=0;
static BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
public static void main (String args[]) throws IOException
[Code] ....
View Replies
View Related
Apr 5, 2014
So first of all we use textpad in our java course (idk why) and the Easy.In method for our input. Any way I have this assignment and we're ask to make a program that input
1) how many numbers were input
2) the largest value
3)smallest value
4) average value and
5) middle/median value.
I manage to figure out the code for the other except the median value. Here's my code
class project2
{
public static void main(String[] args) {
System.out.println("How many numbers you want to input");
int maxItems = EasyIn.getInt();
[Code].....
View Replies
View Related
Oct 18, 2014
I am trying to draw add flowers on a graphics window. I can do this just fine, however the position starts from the far left and goes to the far right. I would like to position the 8 flowers in the center of the screen but can't seem to get the right formula to do so. Here is what I have so far to draw the flower, which is simply a GOval nothing complex:
Java Code:
box.flowers=8;
for (int xpos1 = 10; xpos1 < getWidth() - 40; xpos1 += getWidth() / box.flowers) {
box.drawFlowers(xpos1, 400);
} mh_sh_highlight_all('java');
The box size of the window is 800 by 600. Ideally I would like to place x amount of flowers spread across the middle of the screen. How might I do this???
View Replies
View Related
Jan 7, 2014
package test2;
import java.util.LinkedList;
public class Q {
public static void main(String[] args) {
LinkedList link = new LinkedList();
[Code] ....
So how to delete an element in the middle of the linked list?
View Replies
View Related
Jan 23, 2014
I have a problem with my JTable.
When i run my program i see a JTable with data in it. The first 3 columns are filled with data, the next one is empty. Other columns that come afther the empty one are also filled.
So my 4th column is empty. But it only apears empty, cause when i move the 4th column to the left. The same column that was at 4th place is now at 3th place and filled up with data.
So the 4th column apears empty but it contains data when i move it to the left or the right.
Why does it show an empty column at the 4th place?
Some printscreens to get it clear:
In attachment:
attachment1 = 4th Column is empty
attachement2 = 4th column is moved to 3th place and is filled with data.
View Replies
View Related
Feb 8, 2014
I have a project requiring me to build a program having a user input 3 words, sort them alphabetically and output the middle word. I have done some searching and seem to only come back with results for sorting 2 words. I so far have code to get the user input but I am completely lost as to how to sort them alphabetically.
import java.util.Scanner; //The Scanner is in the java.util package.
public class MiddleString {
public static void main(String [] args){
Scanner input = new Scanner(System.in); //Create a Scanner object.
String str1, str2, str3;
System.out.println("Please enter three word words : "); //Prompt user to enter the three words
[Code]...
we havnt done arrays yet and I THINK i have to do compareTo.....how to use it?
View Replies
View Related
Apr 12, 2014
Basically the class is supposed to have a static variable that keeps track of the number of companies (numberOfCompanies) that have been created and a static method that returns the value of this variable. I need to have a constructor and a method to addEmployee, a method to printCompany, and a toString method. The addEmployee method will check that there is only 1 salesperson, 2 designers, and 4 manufacturing persons at a time and will check that there are no more than 7 employees of the company.
The addEmployee method will return a String indicating what the error is (i.e. "There is already a sales person in this company") or a null if the employee was added. If attempting to name a third company, an error message will be shown. what i have so far but my print company mmethod returns null company class :in which i am obliged to use inputdialog because it says that it cannot return void when i use the showmeassage diaolog.
company class:
import java.util.ArrayList;
import javax.swing.JOptionPane;
public class Company {
private ArrayList<Employees> list ;
private static int numberOfCompanies;
[Code] ....
error message when print button is clicked:
Exception in thread "AWT-EventQueue-0" java.lang.RuntimeException: JOptionPane: parentComponent does not have a valid parent
at javax.swing.JOptionPane.createInternalFrame(Unknown Source)
at javax.swing.JOptionPane.showInternalOptionDialog(Unknown Source)
at javax.swing.JOptionPane.showInternalMessageDialog(Unknown Source)
[Code] ......
View Replies
View Related
Jul 25, 2014
I want to create two thread one thread will print odd number and another thread will print even number. but the number should be in a sequence like
1 2 3 4 5 6 7 8 9 10
View Replies
View Related
Nov 16, 2014
See the below:
public static void main() {
int i; // counter
createDeck(); // this is a function call
// Show the cards in the deck
System.out.println("The deck is as follows:");
for (i=0 ; i < CARDS_IN_DECK ; i++)
[code]....
It is now printing out the value of myDeck[5] but I need to print out first 5 values.
View Replies
View Related
Dec 11, 2014
Java Code:
public class Lab12 {
public static int SumRow(int [][] a){
int row, column, sum=0;
for (row=0;row<2;row++ ) {
sum=0;
for (column=0;column<2;column++) {
sum=sum+a[row][column];
[Code]...
my output is
The sum of row 1 is: 3
The sum of coloumn 0 is: 5
The sum of coloumn 1 is: 5
The max of row 0 is: 4
The max of row 1 is: 2
it is supposed to print the sum of row o first ?
View Replies
View Related
Nov 28, 2014
i have completed a code in java so that it can read spaces in a line but when i run it if i put Line 1 test test for example it will print : [ 3] spaces in Line1 test test what i want to print is [ 3] spaces in "Line1 test test" so the diferences is at " Is there any possible thing that i can do?
class Main
{
public static void main( String args[] )
{
System.out.print( "#Enter text : " );
String text = BIO.getString();
while ( ! text.equals( "END" ) )
{
[Code]...
View Replies
View Related
Oct 14, 2014
I can't print the number that is supposed to come out
public class Skateboard {
private int wheels = 4;
private int trucks = 2;
private int bearings = 8;
private int gripTape = 1;
[code]....
How come sb1.assembly() doesn't return the values? :/
View Replies
View Related
Feb 24, 2014
I am trying to print alphabets from A to F using <c:forEach>
<c:set var="ctr" value="${optListSize}"></c:set> //optListSize is the size of an arraylist
<c:forEach begin="65" end="${ctr}" varStatus="loop" step="1">
<c:out value="<%=String.fromCharCode(64+${ctr})%>"></c:out>
</c:forEach>
I tried the above code but it gives an error. How to go about printing A, B, C, D... incrementally
View Replies
View Related
Feb 20, 2015
How to i print out the first 6 character of a last name even if the last name is and X like Malcolm X or Sung Li. X and Li being the last names
View Replies
View Related
Mar 6, 2015
I amtrying to iterate a value of L,R both are range of BigInteger but its not working
BigInteger L=in.nextBigInteger();
BigInteger R=in.nextBigInteger();
for (BigInteger bi =L;
bi<=bi.compareTo(R);
bi = bi.add(BigInteger.ONE)) {
//Task to do with Numbers
}
I am trying to iterate a for loop in range of L and R but its not working
View Replies
View Related
Mar 26, 2014
I am currently trying to print a Diamond using for-loops but I seem to be confusing my self / over-complicating it.
This is what I have so far [URL]). When I run the code I get [URL].
I want to duplicate it on to the other side but I can't seem to be able to figure out a working for-loop to print it out.
Also, is there a faster/efficient method of doing something like this?
View Replies
View Related
Feb 6, 2015
Implement a Las Vegas slot machine! The machine works as follows. First, it generates three random integers (use import java.lang.Math.*; then call Math.random()*7 to generate a random number between [a,b)) that are in the range of 0-7. Once the numbers are generated, the following rules are used to determine the prize:
- If all three numbers are equal to 7, you are winning $1,000,
- If all three numbers are equal, but not equal to 7, you are winning $500,
- If two of the numbers are equal to 7 and the third one is six, you are winning $400,
- If two numbers are equal, you are winning $100,
- Otherwise you are not winning anything.
And for that I wrote:
import java.lang.Math;
public class Assn1_2150130 {
public static void main(String[] args) {
// Generate three random signle-digit integar from 0-7.
int n1 = (int)(Math.random()*7);
int n2 = (int)(Math.random()*7);
int n3 = (int)(Math.random()*7);
[code]...
But I just can't figure out a way to print out the "YOU WON NOTHING." independently.If I say that n1!=n2 && n2!=n3 && n3!=n1, and then write another line of println. It gives out the number as well as the "NOTHING".
View Replies
View Related
Dec 18, 2014
The value is: ${object1.property1} If the value of the property is null, I want "null" to be printed, like this:
The value is: null But I get an empty string, like: The value is:
I know I can use a ternary operator, but isn't there a simpler/shorter solution? A function (like NVL() in SQL)?
The value is: ${empty object1.property1 ? "null" : object1.property1 }
Not only is this long, but the value expression is typed twice, which is a magnet for bugs.
View Replies
View Related
Apr 3, 2015
I want to write a while loop to print all odd numbers between 1 and 100.
But it gives error. Where is the mistake?
public class pro {
public static void main(String[] args) {
// TODO Auto-generated method stub
int c;
int x=1;
[Code] ....
View Replies
View Related
Feb 11, 2015
I can't figure out how to print this string only five times. I tried to use the * operator, but that doesn't work with strings apparently, unles i'm not importing correctly.
import java.lang.String;
public class Looparray
{
public static void main(String args[] {
for (String myStr= "Hello there!";;) {
System.out.print (myStr);
System.out.print("
");
}
}
}
View Replies
View Related
Apr 29, 2014
I'm not getting text in the Pledge.txt file. Do I need to assign the pledge to a String variable?
Java Code:
import java.io.*;
import java.util.*;
public class ReadMe {
public static void main(String[] args) throws IOException{
File file = new File("Pledge.txt");
PrintWriter output = new PrintWriter(file);
[Code] .....
View Replies
View Related
Oct 20, 2014
On line 45 i am trying to add "-" symbol to my output phone number. As of now the out prints like "1800*45*3569377. I want it to print 1800-3569377, or even more ideal: 1-800-356-9377. When printing normally (system.out.println) I can print symbols, but when I try to print from a for-loop it says "unclosed character literal." import java.util.Scanner;
public class Phone_010473030 {
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
System.out.print("Enter a phone number string: ");
String Phone_num = input.nextLine();
Phone_num = Phone_num.toUpperCase();
[code]....
View Replies
View Related
Oct 5, 2014
I have a form in netbeans java. I want to print the form as it is.Actually I want to print the bill. I am beginner in netbeans java.
View Replies
View Related
Nov 13, 2014
I need to write a program that prints the current time every second. Here is what I have and I am not entirely sure why I'm not.
Java Code:
import java.util.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.Timer;
public class CurrentTime
[Code] .....
View Replies
View Related