Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7734827
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T07:20:52+00:00 2026-06-01T07:20:52+00:00

package GC; import java.util.Scanner; public class main { public static void main(String args[]) {

  • 0
package GC;

import java.util.Scanner;

public class main {
public static void main(String args[]) {
    Scanner input = new Scanner(System.in);
    System.out.println("Calculate exam grade needed(e) or final grade received(f)?");
    String x = input.nextLine();
    if (x == "e"){
        double q1, q2, f, e;
        Scanner inputa = new Scanner(System.in);
        Scanner inputb = new Scanner(System.in);
        Scanner inputc = new Scanner(System.in);

        System.out.print("Quarter 1: ");
        q1 = inputa.nextInt();
        System.out.print("Quarter 2: ");
        q2 = inputb.nextInt();
        System.out.print("Final grade wanted: ");
        f = inputc.nextInt();

        e = 5*(f-0.4*(q1)-0.4*(q2));
        if(e == (int)e){
            System.out.println((int)e);
        }
        else{
            e = 0.01*((int)(e*100));
            System.out.println(e);
        }
    }


    else if (x == "f"){

    }
    else{
        System.out.println("ERROR");
    }



}
}

Even if I input e at the beginning, it always goes to the else statement. I may have done something wrong with getting a String from user input or with my if parameters. What am I missing?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-01T07:20:54+00:00Added an answer on June 1, 2026 at 7:20 am

    You need to use the “equals” compare method. X is a string and there is no overloading operator for “==” on it to compare values.

    Always take a look at the javadocs for an object if you’re unsure.

    http://docs.oracle.com/javase/6/docs/api/java/lang/String.html

    if(x.equals("e")){
    
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

import java.util.scanner; import javax.swing.JOptionPane; public class FirstHomeJavaApplet{ public static void main(String[] args){ int num1=2;
I have this code: package picalculator; //import java.util.Scanner; public class PiCalculator { static int
package homework5; import java.io.*; import java.util.Arrays; public class Main { /** * @param args
Consider this code: package Prova; import java.util.ArrayList; public class Prova { private ArrayList<String> people;
package myProg; import java.util.Scanner; public class oving4a { /** *Øving 4a. Aleksander Pettersen */
I have the following simple Java code: package testj; import java.util.*; public class Query<T>
package org.apache.wicket.examples.guestbook; import java.util.Date; import org.apache.wicket.IClusterable; public class Comment implements IClusterable { private String
The code is also at https://github.com/timp21337/java-generics-example package a; import java.util.List; public interface Container<T> {
package test; import java.awt.*; import java.awt.event.*; import java.awt.geom.Ellipse2D; import java.awt.image.BufferedImage; import javax.swing.*; public class
Here is the server code package echoserver; import java.net.*; import java.io.*; public class EchoServer

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.