Need JAVA programming help.?
The idea says string can’t be resolved to some type, when i type, stringed answer.Anyone help Encourage this should be to ask an individual if he would choose to find out areas of the square and also a triangle.Then asks anyone for information about the shape so that it will get out areas (or hypotenuse) it all works fine except for the STRINGED ANSWER section.Thanks regarding looking!
scan java.util.Scanner;
scan java.util.*;
criminal court class answers
criminal court static emptiness main(String args)
long startTime;
long endTime;
dual time;
Scanner sc=new Scanner(System.in);
startTime = System.currentTimeMillis();
stringed answer;
char any, b;
response = sc.nextLine();
in the event (answer = a)
dual swidth, sarea;
System.out.println(“What is a lenght with one side with the square.”);
swidth = sc.nextInt();
sarea = swidth * swidth;
System.out.println(“The spot is:”);
System.out.println(sarea);
// conclude of reply a
in the event (answer = b)
dual width, height, hypotenuse, spot; // sides of an triangle
System.out.println(“Please type in the width with the triangle”);
width=sc.nextInt();
System.out.println(“Please type in the height with the triangle”);
height=sc.nextInt();
hypotenuse = Mathematics.sqrt( width*width + height*height );
System.out.print(“A triangle with the width with “);
System.out.print(width);
System.out.print(” and also the height with “);
System.out.print(height);
System.out.print(” offers the hypotenuse:”);
System.out.println(hypotenuse);
System.out.println(“\nNow lets obtain the area! “);
spot = (width * height) * 0.5;
System.out.print(“The division of this triangle will be:”);
System.out.print(area);
// conclude of reply b
endTime = System.currentTimeMillis();
occasion = (endTime – startTime) / ONE THOUSAND.0;
System.out.print(“\nRun occasion in seconds was:”);
System.out.println(time);
// conclude main()
// ending class Class1
I see several fundatmental challenges.
You’ve announced chars your and b but haven’t set these individuals.Perhaps a person wanted:
char any = ‘a’;
char b = ‘b’;
Also, your in the event that is erroneous.You wish the realistic == not the work =.You should use == to help compare chars, since they are primitives.You can’t compare things, such since strings, doing this:you’d must use equals or equalsIgnoreCase.
What you almost certainly want is usually:
if( response.charAt(0) == ‘a’ response.charAt(0) == ‘A’ ) // etc
Thus you truly have no need to store that char ‘a’ in a char adjustable.
Java calls its stringed objects ‘String’, not ‘string’.The capital S is not optional.
That said, there are other problems with your code in addition.For case, you are trying to make a stringed comparison applying =.That does work.== fails either.You’ll want to use the actual String.equals() approach.
Should end up being capital “S”, Stringed.String is definitely object with java which always starts off with an uppercase mail.primitives focus on lowercase coorespondence like “int” along with “char”
answer = sc.next();
in the event (answer.compatible (“a”))
in the event (answer.compatible (“b”))
this is what i observe in about two moments of wanting.
Leave a Reply
You must be logged in to post a comment.