Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Newcomers » Newcomers » completely new to java, not new to coding(whats wrong with this?)
completely new to java, not new to coding [message #1802483] Sun, 10 February 2019 15:22 Go to next message
zohaib khurshid is currently offline zohaib khurshidFriend
Messages: 2
Registered: February 2019
Junior Member
whats wrong with this code?
Quote:
package src;
import java.util.Scanner;

public class Class1 {

public static void main(String[] args) {


Scanner input = new Scanner(System.in);

// System.out.print(" weight ");
int weight = 98;
//HOW TO SKIP STATEMENT INCASE CONDITION NOT MET
if (weight >= 100)
{
System.out.print("Please enter your gender as" +
" 'F'or 'M ");
//String gender = input.next();
String gender = "F";
}

int size = (weight/10);
//System.out.format("Size is %d ", size); to check size value

//category
String category = "Snow";

System.out.print(" enter TYPE" +
" 'H' for Hiking or 'B' for Backcountty ");
Scanner scanner = new Scanner(System.in);
String type = scanner.nextLine();
if (type == "H"){
type = "Hiking";
}
else if (type == "B")
{
type = "Backcountry";
}
System.out.format("type is %d", type);

String result = String.format("The price for a %s snowshoes in %s, size %d is $ %d", type, "category",25, 300);
}
}
Quote:

This is the error message i am getting
Exception in thread "main" java.lang.Error: Unresolved compilation problems:
The method format(String, Object[]) in the type PrintStream is not applicable for the arguments (String, String)
The type java.lang.CharSequence cannot be resolved. It is indirectly referenced from required .class files
The method format(Locale, String, Object[]) in the type String is not applicable for the arguments (String, String, String, int, int)

at Class1.main(Class1.java:40)


im using eclipse
Version: Helios Service Release 1
Build id: 20100917-0705

[Updated on: Sun, 10 February 2019 16:05]

Report message to a moderator

Re: completely new to java, not new to coding [message #1802488 is a reply to message #1802483] Sun, 10 February 2019 18:36 Go to previous messageGo to next message
Michael Lüssem is currently offline Michael LüssemFriend
Messages: 6
Registered: February 2019
Junior Member
Hi,

try this:

if (type.equals("H")){
	type = "Hiking";
	}
	else if (type.equals("B"))
	{
	type = "Backcountry";
	}
	System.out.format("type is %s", type);


1. to compare strings use equals()-method, not "=="
2. the format needs %s for a string

Greetings!

Michael - germany
Re: completely new to java, not new to coding [message #1802490 is a reply to message #1802488] Sun, 10 February 2019 20:53 Go to previous messageGo to next message
zohaib khurshid is currently offline zohaib khurshidFriend
Messages: 2
Registered: February 2019
Junior Member
Thankyou bro from germany ^_^
Now im getting this single error
Quote:
Error: Could not find or load main class Assignment2
Re: completely new to java, not new to coding [message #1802558 is a reply to message #1802490] Mon, 11 February 2019 20:59 Go to previous message
Michael Lüssem is currently offline Michael LüssemFriend
Messages: 6
Registered: February 2019
Junior Member
Please give us the whole code, the error and a short discription of what you would like to do and how your program should react.
Previous Topic:How can I installing Eclipse and packages from marketplace in a USB stick ?
Next Topic:[SOLVED] Eclipse failed to launch workspace
Goto Forum:
  


Current Time: Sat Aug 17 15:07:12 GMT 2019

Powered by FUDForum. Page generated in 0.03030 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top